class House {
    constructor(data) {
        this.createHouseFromData(data);
    }

    createHouseFromData(data) {
        this.id = data.id;
        this.houseId = data.houseId;
        this.username = data.username;
        this.address = data.address;
        this.zjz = data.zjz || [];
        this.note = data.note;
        this.groupId = data.groupId;
        this.house = data.house || [];
        this.cg = data.cg || [];
        this.flag = data.flag;
        this.objectId = data.objectId;
        this.structure = data.structure;
        this.community = data.community;
        this.site = data.site;
        this.isNew = (0 != data.isNew && 1 != data.isNew) ? 0 : data.isNew;
        this.isIllegal = (0 != data.isNew && 1 != data.isNew) ? 0 : data.isIllegal;
        this.isCheck = (0 != data.isNew && 1 != data.isNew && 2 != data.isNew) ? 0 : data.isCheck;
        this.originalDrawDate = data.originalDrawDate;
        this.currentDrawDate = data.currentDrawDate;
        this.createTime = new Date().getTime();
        this.UpdateTime = new Date().getTime();
        this.cellphone = data.cellphone;
        this.contrastBefore = data.contrastBefore || [];
        this.contrastDuring = data.contrastDuring || [];
        this.contrastAfter = data.contrastAfter || [];
        this.area = data.area;
        this.company = data.company;
        this.submitter = data.submitter;
        this.isPlough = data.isPlough;
        this.type = data.type;
    }

    toDb() {
        return {
            houseId: this.houseId,
            username: this.username,
            address: this.address,
            note: this.note,
            groupId: this.groupId,
            flag: this.flag,
            objectId: this.objectId,
            structure: this.structure,
            community: this.community,
            site: this.site,
            isNew: this.isNew,
            isIllegal: this.isIllegal,
            isCheck: this.isCheck,
            cellphone: this.cellphone,
            createTime: this.createTime,
            UpdateTime: this.UpdateTime,
            area: this.area,
            originalDrawDate: this.originalDrawDate,
            currentDrawDate: this.currentDrawDate
        }
    }

    updatetoDoc() {
        return {
            id: this.id,
            houseId: this.houseId,
            address: this.address,
            groupId: this.groupId,
            structure: this.structure,
            community: this.community,
            site: this.site,
            UpdateTime: this.UpdateTime,
            area: this.area,
            originalDrawDate: this.originalDrawDate,
            currentDrawDate: this.currentDrawDate
        }
    }

    updatetoDb() {
        return {
            id: this.id,
            houseId: this.houseId,
            username: this.username,
            address: this.address,
            note: this.note,
            groupId: this.groupId,
            flag: this.flag,
            objectId: this.objectId,
            structure: this.structure,
            community: this.community,
            site: this.site,
            isNew: this.isNew,
            isIllegal: this.isIllegal,
            UpdateTime: this.UpdateTime,
            cellphone: this.cellphone,
            isCheck: this.isCheck,
            area: this.area,
            originalDrawDate: this.originalDrawDate,
            currentDrawDate: this.currentDrawDate
        }

    }

    updatetoReport() {
        return {
            id: this.id,
            username: this.username,
            note: this.note,
            isNew: this.isNew,
            isIllegal: this.isIllegal,
            UpdateTime: this.UpdateTime,
            isCheck: this.isCheck,
            company: this.company,
            submitter: this.submitter,
            isPlough: this.isPlough,
            type: this.type
        }

    }

    getZjz() {
        return this.zjz
    }

    getHouse() {
        return this.house
    }

    getCg() {
        return this.cg
    }

    getContrastBefore() {
        return this.contrastBefore
    }

    getContrastDuring() {
        return this.contrastDuring
    }

    getContrastAfter() {
        return this.contrastAfter
    }
}

module.exports = House